cmake_minimum_required(VERSION 3.5)

PROJECT(testiocp)

IF(CMAKE_CL_64) 
set(platform x64) 
message("is x64")
ELSE(CMAKE_CL_64) 
set(platform x86) 
message("is x86")
ENDIF(CMAKE_CL_64)

# https://zhuanlan.zhihu.com/p/196772123
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
    set( my_std_pre "/std:" )
else()
    set( my_std_pre "-std=" )
endif()

set( basic_cxx17 "c++17" )
set( str_cxx17 "${my_std_pre}${basic_cxx17}" )

include( CheckCXXCompilerFlag )
check_cxx_compiler_flag( "${str_cxx17}" _cpp_17_flag_supported )
if ( _cpp_17_flag_supported )
    set( CMAKE_CXX_STANDARD 17 )
	message("17  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
else()
    set( CMAKE_CXX_STANDARD 11 )
	message("11  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
endif()

function(group_by_dir reduce_dir)
	message("")
	message("reduce_dir=${reduce_dir}")
	message("ARGV0=${ARGV0}")
	message("ARGN=${ARGN}")
	foreach(var_file ${ARGN})
		message("")
		message("var_file=${var_file}")
		get_filename_component(full_name "${var_file}" ABSOLUTE)
		message("full_name=${full_name}")
		get_filename_component(parent_dir "${full_name}" PATH)
		message("parent_dir=${parent_dir}")
		string(REPLACE "${reduce_dir}" "" GROUP "${parent_dir}")
		message("GROUP=${GROUP}")
		string(REPLACE "/" "\\" GROUP "${GROUP}")
		message("GROUP=${GROUP}")
		source_group("${GROUP}" FILES "${var_file}")
		message("${var_file} ====> ${GROUP}")
		message("")
	endforeach()
endfunction(group_by_dir)

ADD_DEFINITIONS(/W3 /wd"4005" /wd"4996" /wd"4819" /wd"4091" /wd"4099" /wd"4800" /wd"4334" /MP /Gm- /WX- /bigobj)

message("PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}")


option(FOO_USE_EXTERNAL_JSON "Use an external JSON library" OFF)

#add_subdirectory(thirdparty)



# Note that the namespaced target will always be available regardless of the
# import method
# target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)


ADD_SUBDIRECTORY(Listing1.1)
ADD_SUBDIRECTORY(Listing2.1)
ADD_SUBDIRECTORY(Listing2.2)
ADD_SUBDIRECTORY(Listing2.3)
ADD_SUBDIRECTORY(Listing2.4)
ADD_SUBDIRECTORY(Listing2.5)
ADD_SUBDIRECTORY(Listing2.6)
ADD_SUBDIRECTORY(Listing2.7)
ADD_SUBDIRECTORY(Listing2.8)
ADD_SUBDIRECTORY(Listing2.9)
ADD_SUBDIRECTORY(Listing3.1)
ADD_SUBDIRECTORY(Listing3.2)
ADD_SUBDIRECTORY(Listing3.3)
ADD_SUBDIRECTORY(Listing3.4)
ADD_SUBDIRECTORY(Listing3.5)
ADD_SUBDIRECTORY(Listing3.6)
ADD_SUBDIRECTORY(Listing3.7)
ADD_SUBDIRECTORY(Listing3.8)